<template>
	<!-- 轮播图 -->
	<view class="home">
		<swiper indicator-dots circular autoplay interval="2500">
			<swiper-item>
				<image src="https://img.alicdn.com/tfs/TB1l6mOMBr0gK0jSZFnXXbRRXXa-520-280.jpg_q90_.webp"></image>
			</swiper-item>
			<swiper-item>
				<image src="https://aecpm.alicdn.com/simba/img/TB1XotJXQfb_uJkSnhJSuvdDVXa.jpg"></image>
			</swiper-item>
			<swiper-item>
				<image src="https://img.alicdn.com/tfs/TB1yA1jf8Bh1e4jSZFhXXcC9VXa-520-280.jpg_q90_.webp"></image>
			</swiper-item>
		</swiper>
	<!-- 导航栏 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">
				推荐商品
			</view>
			<view class="goods_list">
				<goods-item  v-for="(item,index) in data" :key="index" :img="item.img" :price="item.price" :content="item.content"></goods-item>
			</view>
		</view>
		
	</view>
</template>

<script>
	import goodsItem from "../../components/goods-item/goods-item.vue"
	export default {
		data() {
			return {
				navs: [
					{
						icon: 'iconfont icon-ziyuan',
						title: '超市',
						path: '/pages/goods/goods'
					},
					{
						icon: 'iconfont icon-guanyuwomen',
						title: '联系我们',
						path: '/pages/contact/contact'
					},
					{
						icon: 'iconfont icon-tupian',
						title: '社区图片',
						path: '/pages/pics/pics'
					},
					{
						icon: 'iconfont icon-shipin',
						title: '学习视频',
						path: '/pages/videos/videos'
					}
				],
				list: [
					{
						img: 'https://gw.alicdn.com/bao/upload/TB16Ya8qLb2gK0jSZK9XXaEgFXa.jpg_Q75.jpg',
						price: ['¥3199','¥3299'],
						content:'Huawei/华为MatePad Pro平板电脑笔记本二合一新品轻薄全面屏影音无线充电'
					}
				],
				data: [],
				loadMoreText: "加载中...",
				showLoadMore: false
			}
		},
		onLoad() {
			this.initData();
		},
		onUnload() {
			this.loadMoreText = "加载更多",
			this.showLoadMore = false;
		},
		onReachBottom() {
			console.log("onReachBottom");
			if (this.data.length > 20) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}
			this.showLoadMore = true;
			setTimeout(() => {
				this.setListData();
			}, 300);
		},
		onPullDownRefresh() {
			console.log('onPullDownRefresh');
			this.initData();
		},
		methods: {
			initData(){
				this.data=[];
				setTimeout(() => {
					for (var i = 0; i < 5; i++) {
						this.data.push(this.list[0])
					}
					uni.stopPullDownRefresh();
				}, 300);
			},
			setListData() {
				for (var i = 0; i < 6; i++) {
					this.data.push(this.list[0])
				}
			},
			navItemClick (url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 500rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
	.nav {
		display: flex;
		.nav_item {
			width: 25%;
			text-align: center;
			view {
				width: 120rpx;
				height: 120rpx;
				background-color: #da2911;
				border-radius: 50%;
				margin: 10px auto;
				line-height: 120rpx;
				color: #FFFFFF;
				font-size: 50rpx;
			}
			text {
				font-size: 30rpx;
			}
		}
	}
	.hot_goods {
		background-color: #eee;
		overflow: hidden;
		.tit {
			height: 50px;
			text-align: center;
			line-height: 50px;
			background-color: #fff;
			letter-spacing: 15px;
			color: #da2911;
			margin: 7px 0;
		}
		.goods_list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 0 10rpx;
		}
	}
</style>
